
x=0:0.5:10;
y=[2.9,2.7,4.8,5.3,7.1,7.6,7.7,7.6,9.4,9.0,9.6,10.0,10.2,9.7,8.3,8.4,9.0,8.3,6.6,6.7,4.1];
n=length(x);
A=[ones(n, 1), x_data', x_data'.^2];
[Q,R]=qr(A, 0);
a1=R\(Q' * y_data');
disp('系数为');
disp(['a0: ', num2str(a(1)), ', a1: ', num2str(a(2)), ', a2: ', num2str(a(3))]);
disp("函数表达式：-0.23844x^2+2.6704x+2.1757");
A1 = cond(A'*A, 2);
R1 = cond(R, 2);

disp(['A 的条件数: ', num2str(A1)]);
disp(['R 的条件数: ', num2str(R1)]);


